package com.monolithiot.sso.dao.mapper;

import com.monolithiot.sso.common.entity.Authorization;
import com.monolithiot.sso.dao.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

/**
 * 2018/12/11 Create by 郭文梁
 * AuthorizationMapper
 * 授权数据库访问层
 *
 * @author 郭文梁
 * @date 2018/12/11
 */
@Repository
public interface AuthorizationMapper extends BaseMapper<Authorization> {
    /**
     * 通过Token查询授权信息，同时抓取用户信息
     *
     * @param token 令牌
     * @return Authorization with User
     */
    Authorization selectByTokenWithUser(@Param("token") String token);

    /**
     * 通过用户ID查找有效的（未过期的）授权
     *
     * @param userId 用户ID
     * @return 授权
     */
    Authorization selectAvailableByUserId(@Param("userId") Integer userId);

    /**
     * 删除数据库中的过期授权
     *
     * @return 删除的授权数量
     */
    int deleteOverdue();
}
